package com.jd.common;

import com.jd.enums.GoodEnums;
import com.jd.enums.ResultEnums;

/**
 * Created by Administrator on 2017/9/21/021.
 */
public class AjaxResult {
    private Integer code;
    private String msg;
    private Object data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public AjaxResult() {

    }

    public AjaxResult(Integer code, String msg, Object data) {

        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public AjaxResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public AjaxResult(Object result) {
        if(result instanceof GoodEnums){
            this.code=((GoodEnums)result).getCode();
            this.msg=((GoodEnums)result).getMsg();
        }else if(result instanceof ResultEnums){
            this.code=((ResultEnums)result).getCode();
            this.msg=((ResultEnums)result).getMsg();
        }
    }

    public AjaxResult(Object result,Object data) {
        if(result instanceof GoodEnums){
            this.code=((GoodEnums)result).getCode();
            this.msg=((GoodEnums)result).getMsg();
        }else if(result instanceof ResultEnums){
            this.code=((ResultEnums)result).getCode();
            this.msg=((ResultEnums)result).getMsg();
        }
        this.data=data;
    }

    @Override
    public String toString() {
        return "AjaxResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
